<template>
  <div class="app-container">

    <el-form class="formList" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
      label-width="80px">
      <el-row>

        <el-form-item label="关键词" prop="commentContent">
          <el-input v-model="queryParams.commentContent" placeholder="请输入关键词" clearable size="small"
            style="width: 232px" class="input-rule" />
        </el-form-item>

        <el-form-item label="商品名称" prop="productName">
          <el-input v-model="queryParams.productName" placeholder="请输入商品名称" clearable size="small" style="width: 232px"
            class="input-rule" />
        </el-form-item>

        <el-form-item label="商品分类" prop="categoryUid">
          <el-cascader :props="{ checkStrictly: true }" v-model="queryParams.categoryUid" :options="categoryOptions" clearable filterable
            style="width: 232px" class="input-rule">
          </el-cascader>
        </el-form-item>

      </el-row>
      <el-row>

        <el-form-item label="是否回复" prop="commentType">
          <el-select v-model="queryParams.commentType" clearable placeholder="请选择" style="width: 232px">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable size="small" class="input-rule"
            style="width: 232px" />
        </el-form-item>

        <el-form-item label="评论时间" prop="applyAuthTimeArray">
          <el-date-picker v-model="queryParams.applyAuthTimeArray" type="daterange" align="right" style="width: 232px"
            value-format="yyyy-MM-dd" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item style="margin-left: 22px">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-row>
    </el-form>

    <el-row class="row-mbinfo">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <div class="divTable">
      <el-table v-loading="loading" :data="commentList" border style="font-size:12px">
        <!-- <el-table-column label="评价视频" align="left" width="120" height="120">
        <template slot-scope="scope">
          <video style="width: 80px;height: 80px;margin-left: 5px"
            v-if="scope.row.commentVideo != '' && scope.row.commentVideo!=null" :src="scope.row.commentVideo "
            controls="controls">
            您的浏览器不支持视频播放
          </video>
        </template>
      </el-table-column> -->
        <el-table-column label="评价内容" align="left" min-width="300">
          <template slot-scope="scope">
            <div class="pro_evaluate_data">
              <div class="item_evaluate">服务：<i v-for="(val, idx) in 5" :key="idx" :class="[scope.row.serviceScoreNum >= idx + 1? 'el-icon-star-on': 'el-icon-star-off', 'start_icon']"></i></div>
              <div class="item_evaluate">商品：<i v-for="(val, idx) in 5" :key="idx" :class="[scope.row.productScoreNum >= idx + 1? 'el-icon-star-on': 'el-icon-star-off', 'start_icon']"></i></div>
              <div class="item_evaluate">物流：<i v-for="(val, idx) in 5" :key="idx" :class="[scope.row.logisticsScoreNum >= idx + 1? 'el-icon-star-on': 'el-icon-star-off', 'start_icon']"></i></div>
            </div>
            <div align="left" class="line_div">{{ scope.row.commentContent }}</div>

            <div align="left" class="show_commment_img" v-if="scope.row.carouselImgs != null && scope.row.carouselImgs != '' " slot="reference">
              <!-- <span>上传图片：</span> -->
              <el-image style="display:block;margin: 5px 5px 0 0" v-for="(imgs,index) in scope.row.carouselImgs"
                :key="index" :src="imgs" class="image-rows" :preview-src-list="scope.row.carouselImgs">
              </el-image>
            </div>
            <div align="left" class="line_div" style="color: #999">{{ scope.row.commentTime }}</div>
          </template>
        </el-table-column>

        <el-table-column label="订单信息" align="left" min-width="200">
          <template slot-scope="scope">
            <div align="left" class="line_div">订单编号：{{ scope.row.orderNo }}</div>
            <div align="left" class="line_div">买家昵称：{{ scope.row.memberNickName }}</div>
            <div class="show_pro_info">
              <div align="left">
                <el-image v-if="scope.row.productImgUrl != null && scope.row.productImgUrl != '' " slot="reference"
                  :src="scope.row.productImgUrl" class="image-rows" :preview-src-list="[scope.row.productImgUrl]">
                </el-image>
              </div>
              <div style="margin-left: 5px; flex: 1;overflow: hidden">
                <div class="show_pro_title" size="mini" type="text" @click="handledetail(scope.row)">
                   <el-tooltip class="item" effect="light" :content="scope.row.productName" placement="top">
                    <span class="show_pro_title_txt">{{ scope.row.productName }}</span>
                  </el-tooltip>

                </div>
                <span>{{ scope.row.valuesDesc }}</span>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="回复信息" align="left" min-width="150">
          <template slot-scope="scope">
            <div v-if="scope.row.merchantName!=null && scope.row.merchantName!=''" class="line_div">
              回复账号：{{ scope.row.merchantName }}
            </div>
            <div class="line_div">{{ scope.row.merchantTxt }}</div>
            <div>{{ scope.row.merchantTime }}</div>
          </template>
        </el-table-column>
        <el-table-column width="130" label="操作" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button style="display: block;margin: 0" size="mini" type="text" icon="el-icon-zoom-in" @click="chakan(scope.row)">查看订单
            </el-button>
            <el-button v-if="scope.row.commentVideo" style="display: block;margin: 0" size="mini" type="text"
              icon="el-icon-video-play" @click="playVideo(scope.row.commentVideo)">查看评论视频
            </el-button>
            <el-button v-if="scope.row.merchantName == null || scope.row.merchantName==''" style="display: block;margin: 0"
              size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['product:comment:edit']">回复/互动
            </el-button>
            <el-button v-if="scope.row.isShow ==  '0'" size="mini" type="text" icon="el-icon-check" style="display: block;margin: 0"
              @click="pin(scope.row,'1')">显示
            </el-button>
            <el-button v-if="scope.row.isShow ==  '1' " size="mini" type="text" icon="el-icon-close" style="display: block;margin: 0"
              @click="pin(scope.row,'0')">屏蔽
            </el-button>

          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <el-dialog :title="titleMe" :visible.sync="openMe" width="500px" append-to-body>

      <el-input :rows="5" type="textarea" placeholder="该条评论暂无互动，快捷回复参与互动" v-model="merchantTxt" style="width: 450px"
        maxlength="200" show-word-limit>
      </el-input>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">回 复</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <productDetail :uid="productViewUid" :key="productViewUid"></productDetail>
    </el-dialog>
    <el-dialog title :visible.sync="dialogPlay" @close="closeDialog">
      <video :src="videoUrl" controls autoplay class="video" style="height:700px;width:100%"></video>
    </el-dialog>

    <!-- 查看订单子对话框 -->
    <el-dialog :title="viewTitleo" :visible.sync="viewOpeno" width="1400px" append-to-body>
      <order v-if="orderVo" :info="orderVo"></order>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listComment,
    getComment,
    delComment,
    addComment,
    updateComment,updateCommentShow
  } from "@/api/product/comment";
  import Editor from '@/components/Editor';
  import productDetail from '@/components/Product/productDetail';
  import {
    getInfo
  } from "@/api/order/info";
  import order from "@/components/Order/order";
  import {
    selectOptions
  } from "@/api/product/category";

  export default {
    name: "Comment",
    components: {
      Editor,
      productDetail,
      order
    },
    data() {
      return {
        productId:null,
        orderVo: null,
        viewTitleo: null,
        viewOpeno: null,
        merchantTxt: null,
        commentUid: null,
        openMe: false,
        titleMe: '快捷回复',
        // 预览图片
        carouselImgs: [],
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }, {
            text: '最近六个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 180)
              picker.$emit('pick', [start, end])
            }
          }]
        },
        // 商品分类
        categoryOptions: [],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 下拉框的值
        options: [{
          value: '1',
          label: '已回复'
        }, {
          value: '0',
          label: '未回复'
        }],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 商品评论信息表格数据
        commentList: [],
        // 弹出层标题
        title: "",
        //查看详细标题
        viewTitle: "",
        // 是否显示弹出层
        open: false,
        //是否显示查看详细弹出层
        viewOpen: false,
        //查看详细数据
        showData: [],
        // 用于查询详细的uid
        productViewUid: 0,
        // 状态字典
        dataStatusOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderNo: null,
          commentType: null,
          productName: null,
          categoryUid: null,
          commentContent: null,
          applyAuthTimeArray: [],
          categoryUidOne: null,
          categoryUidTwo: null,
          categoryUidThree: null,
          startTime: null,
          endTime: null,
        },
        columns: [],
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          merchantTxt: [{
            required: true,
            message: "回复内容不能为空",
            trigger: "blur"
          }]
        },
        videoUrl: '',
        dialogPlay: false
      };
    },
    created() {
      // 默认时间
      let date1 = new Date();
      let date2 = new Date(date1);
      date2.setDate(date1.getDate() - 90);
      let time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();
      let time2 = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
      this.queryParams.applyAuthTimeArray.push(time2);
      this.queryParams.applyAuthTimeArray.push(time1);
      this.getList();
      this.getDicts("sys_data_status").then(response => {
        this.dataStatusOptions = response.data;
      });
      selectOptions().then(response => {
        this.categoryOptions = response.data;
      });
    },
    methods: {
      pin(row,obj){
        let data = {commentUid:row.commentUid,isShow:obj,product:row.productUid};
        updateCommentShow(data).then(response =>{
          this.$message.info("操作成功！")

          this.getList();
        });
      },
      chakan(row) {
        const orderUid = row.orderUid;
        /*this.orderVo = null;
        getInfo(orderUid).then(response => {
          this.orderVo = response.data;
          this.viewOpeno = true;
          this.viewTitleo = "订单详情";
        });*/
         this.$router.push("/order/detail/" + orderUid);
      },
      closeDialog() {
        this.dialogPlay = false;
        this.videoUrl = ''
      },
      playVideo(v) {
        this.dialogPlay = true;
        this.videoUrl = v;
      },
      /** 查询商品评论信息列表 */
      getList() {
        this.loading = true;
        if (this.queryParams.categoryUid != null && this.queryParams.categoryUid.length > 0) {
          let uidArray = this.queryParams.categoryUid;
          this.queryParams.categoryUidOne = uidArray[0];
          if (uidArray.length > 1) {
            this.queryParams.categoryUidTwo = uidArray[1];
          }
          if (uidArray.length > 2) {
            this.queryParams.categoryUidThree = uidArray[2];
          }
        }
        if (this.queryParams.applyAuthTimeArray != null && this.queryParams.applyAuthTimeArray.length > 0) {
          let arr = this.queryParams.applyAuthTimeArray;
          this.queryParams.startTime = arr[0] + " 00:00:00";
          this.queryParams.endTime = arr[1] + " 23:59:59";
        }
        listComment(this.queryParams).then(response => {
          this.commentList = response.rows;
          this.total = response.total;
          this.loading = false;
          this.queryParams.categoryUidOne = null;
          this.queryParams.categoryUidTwo = null;
          this.queryParams.categoryUidThree = null;
          this.queryParams.startTime = null;
          this.queryParams.endTime
        });
      },
      // 状态字典翻译
      dataStatusFormat(row, column) {
        return this.selectDictLabel(this.dataStatusOptions, row.dataStatus);
      },
      // 取消按钮
      cancel() {
        this.reset();
        this.openMe = false;

      },
      // 表单重置
      reset() {
        this.form = {
          commentUid: null,
          commentType: null,
          imagesUrl: null,
          commentContent: null,
          commentVideo: null,
          commentTime: null,
          productUid: null,
          productName: null,
          productImgUrl: null,
          dataStatus: null,
          updateUid: null,
          updateTime: null,
          memberUid: null,
          memberName: null,
          memberNickName: null,
          memberHeadUrl: null,
          serviceScore: null,
          productScore: null,
          logisticsScore: null,
          isShow: null,
          orderUid: null,
          skuUid: null,
          platformUid: null,
          merchantTxt: null,
          merchantName: null,
          merchantTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 查看详情按钮操作 **/
      handleShowDetail(row) {
        this.viewOpen = true;
        this.viewTitle = "查看商品评论信息";
        this.showData = [];
        this.columns.forEach(item => {
          this.showData.push({
            label: item.label,
            value: row[item.dataIndex]
          })
        })
      },
      handCloseDetail() {
        this.viewOpen = false
        this.showData = []
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.commentUid = row.commentUid;
        this.merchantTxt = "";
        this.productId = row.productUid;
        this.openMe = true;
      },
      /** 提交按钮 */
      submitForm() {
        console.log(this.commentUid)
        console.log(this.merchantTxt)
        if (this.merchantTxt != null && this.merchantTxt != "" && this.commentUid != null) {
          let data = {
            merchantTxt: this.merchantTxt,
            commentUid: this.commentUid,
            productUid: this.productId,
          };
          updateComment(data).then(response => {
            this.msgSuccess("回复成功");
            this.openMe = false;
            this.getList();
          });
        } else {
          this.$message({
            message: '回复内容不能为空',
            type: 'warning'
          });
        }
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const commentUids = row.commentUid || this.ids;
        this.$confirm('是否确认删除商品评论信息编号为"' + commentUids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delComment(commentUids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('product/comment/export', {
          ...this.queryParams
        }, `product_comment.xlsx`)
      },
      /** 查询详细 */
      handledetail(row) {
        const productUid = row.productUid
        this.$router.push("/product/detail/" + productUid);
      }
    }
  };
</script>

<style lang="scss" scoped>
  .line_div {
    margin-bottom: 0px;
  }

  .show_commment_img {
    display: flex;
    flex-wrap: wrap;
  }
  .pro_evaluate_data {
    display: flex;
    align-items: center;
    font-size: 12px;
    .item_evaluate {
      display: flex;
      align-items: center;
      &:not(:first-child) {
        margin-left: 15px;
      }
      .start_icon {
        color: #EF9C00;
      }
      .el-icon-star-on {
        font-size: 14px;
      }
      .el-icon-star-off {
        font-size: 12px;
      }
    }
  }
  .show_pro_info {
    display: flex;

    .show_pro_title {
      color: #5DA9EF;
      width: 100%;
      overflow: hidden;
      text-overflow:ellipsis;
      white-space: nowrap;
      .show_pro_title {
        width: 100%;
        display: inline-block;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
      }
      &:hover {
        cursor: pointer;
      }
    }
  }
</style>
